package java8_16;

import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class DinnerOrder {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        //1,初始化订单信息
        //最多包含有4条订单信息
        String[] names = new String[4]; // 保存订餐人名称
        String[] dishMegs = new String[4]; // 保存菜品名
        int[] dishNum = new int[4]; //保存菜品序号
        int[] num = new int[4];   //菜品份数
        int[] times = new int[4]; // 保存送餐时间
        String[] addresses = new String[4]; // 保存送餐地址
        int[] states = new int[4]; // 保存订单状态： 0：已预订 1：已完成
        double extra = 0;  //外送费；
        double[] sumPrices = new double[4]; // 保存订单的总金额


        String[] dish = new String[]{"红烧带鱼", "鱼香肉丝", "时令鲜蔬"};  //菜单
        double[] price = new double[]{38.0, 20.0, 10.0};  //价格
        int[] good = new int[]{0, 0, 0};    //点赞数

        names[0] = "张晴";
        dishMegs[0] = "红烧带鱼";
        num[0] = 2;
        times[0] = 12;
        addresses[0] = "天虎路207号";
        states[0] = 1;
        sumPrices[0] = 76.0;

        names[1] = "张晴";
        dishMegs[1] = "鱼香肉丝";
        num[1] = 2;
        times[1] = 18;
        addresses[1] = "天虎路207号";
        states[1] = 0;
        sumPrices[1] = 45.0;


        //2,访问订单信息
        System.out.println("欢迎使用\"吃货联盟订餐系统\"");
        System.out.println("**********************************");
        while (true) {
            System.out.println("**********************************");
            System.out.println("1.我要订餐");
            System.out.println("2.查看餐袋");
            System.out.println("3.签收订单");
            System.out.println("4.删除订单");
            System.out.println("5.我要点赞");
            System.out.println("6.退出系统");
            System.out.println("**********************************");
            System.out.print("请选择:");
            int ch = in.nextInt();
            switch (ch) {


                case 1:
                    System.out.println("***我要订餐***");
                    int i=0;
                    for (i = 0; i < names.length; i++) {
                        if (names[i] == null)
                            break;
                    }
                    System.out.println("请输入订餐人姓名:");
                    names[i] = in.next();
                    System.out.println("请看菜单：");
                    System.out.println("序号   菜名    价格   点赞数");
                    for (int j = 0; j < dish.length; j++) {
                        System.out.println((j + 1) + "      " + dish[j] + "    " + price[j] + "      " + good[j]);
                    }
                    System.out.println("请选择你要点的菜品编码：");
                    dishNum[i] = in.nextInt();
                    int xiaobiao=dishNum[i];
                    //这个xiabiao获得价格和菜名！！！
                    //>>>price[dishNum[i]]
                    dishMegs[i] = dish[i];
                    System.out.println("请选择你要点的份数：");
                    num[i] = in.nextInt();
                    System.out.println("请输入送餐时间10-20点间整点送菜：");
                    times[i] = in.nextInt();
                    while (times[i] < 10 || times[i] > 20) {
                        System.out.print("您输入的时间有误，请重新输入：");
                        times[i] = in.nextInt();
                    }
                    System.out.println("请输入送餐地址：");
                    addresses[i] = in.next();
                    System.out.println("订餐成功！");
                    extra = (price[i] * num[i] > 50) ? 0 : 6;
                    sumPrices[i] = price[i] * num[i] + extra;
                    System.out.println("您订购的是：" + dish[i]);
                    System.out.println("送餐时间是（送餐时间是10点至20点间整点送餐）："
                            + times[i] + "点");
                    System.out.println("餐费是：" + price[i] * num[i] + "元,送餐费："
                            + extra + "元，" + "总价是：" + sumPrices[i] + "元");
                    states[i] = 0;
                    continue;


                case 2:
                    System.out.println("***查看餐袋***");
                    System.out.println("序号    订餐人    餐品信息    送餐日期    送餐地址    总金额    订单状态");
                    for (int k = 0; k < names.length; k++) {
                        if (names[k] != null) {
                            System.out.println((k + 1) + "        " + names[k] + "     "
                                    + dishMegs[k] + num[k] + "份    " + times[k] + "      "
                                    + addresses[k] + "    " + sumPrices[k] + "      "
                                    + states[k]);
                        }
                    }
                    continue;


                case 3:
                    System.out.println("***签收订单***");
                    System.out.println("请输入需要签收的订单！");
                    int a = in.nextInt();
                    if (a > names.length || a < 0) {
                        System.out.println("输入了无效订单号，无法签收");
                        break;
                    } else if (names[a - 1] == null) {
                        System.out.println("顾客姓名为空，订单不存在，无法签收");
                        break;
                    } else if (states[a - 1] == 1) {
                        System.out.println("订单已经签收，无法执行");
                        break;
                    } else {
                        states[a - 1] = 1;
                        System.out.println("订单签收成功！");
                        continue;
                    }


                case 4:
                    System.out.println("***删除订单***");
                    System.out.println("请输入要删除的订单序号:");
                    int b = in.nextInt();
                    if (b > names.length || b < 0) {
                        System.out.println("输入了无效订单号，无法删除");
                    } else if (names[b - 1] == null) {
                        System.out.println("订单不存在，无法删除");
                    } else if (states[b - 1] == 0) {
                        System.out.println("您选择的订单未签收，无法删除");
                    } else {
                        for (int m = b - 1; m < names.length - 1; m++) {
                            names[m] = names[m + 1];
                            dishMegs[m] = dishMegs[m + 1];
                            times[m] = times[m + 1];
                            addresses[m] = addresses[m + 1];
                            dishNum[m] = dishNum[m + 1];
                            num[m] = num[m + 1];
                            states[m] = states[m + 1];
                            sumPrices[m] = sumPrices[m + 1];
                        }
                        names[names.length - 1] = null;
                        dishMegs[names.length - 1] = null;
                        times[names.length - 1] = 0;
                        addresses[names.length - 1] = null;
                        dishNum[names.length - 1] = 0;
                        num[names.length - 1] = 0;
                        states[names.length - 1] = 0;
                        sumPrices[names.length - 1] = 0;
                        System.out.println("删除成功！");
                        continue;
                    }


                case 5:
                    System.out.println("***我要点赞***");
                    System.out.println("序号   菜名    单价   点赞数");
                    for (int q = 0; q < dish.length; q++) {
                        System.out.println((q + 1) + "    " + dish[q] + "  " + price[q] + "    " + good[q]);
                    }
                    System.out.println("请输入你要点赞的菜品：");
                    int c = in.nextInt();
                    if (c >= 1 && c <= dish.length) {
                        good[c - 1] += 1;
                        System.out.println("点赞成功！");
                        continue;
                    } else {
                        System.out.println("抱歉，这个餐品不存在哦");
                        continue;
                    }


                case 6:
                    return;


                default:
                    System.out.println("抱歉，你输入的指令不存在，请重试");
                    continue;

            }

        }


    }
}
